package creationPattern.Factory.Factory_03.factory;

import creationPattern.Factory.Factory_03.factory.impl.DiscountFactory;
import creationPattern.Factory.Factory_03.factory.impl.SmallGiftFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * 抽象工厂的工厂 - 用来创建抽象工厂类对象
 */
public class FreeGoodsFactoryMap {
    // 创建一个map集合，用来保存工厂对象;
    private static final Map<Integer, FreeGoodsFactory> cachedFactorys = new HashMap<>();

    static {
        // 结合单例模式 - 工厂的单例
        cachedFactorys.put(1,new DiscountFactory());
        cachedFactorys.put(2,new SmallGiftFactory());
    }

    public static FreeGoodsFactory getParserFactory(Integer type){
        FreeGoodsFactory freeGoodsFactory = cachedFactorys.get(type);
        return freeGoodsFactory;
    }
}
